package com.tangly.codeing.service.impl;

import com.tangly.codeing.dao.SysUserRoleDao;
import com.tangly.codeing.model.SysUserRole;
import com.tangly.codeing.service.SysUserRoleService;
import com.tangly.codeing.utils.PageInfo;
import com.tangly.codeing.utils.ReturnT;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户角色
 * @author tangbing
 * @date 2019-05-06
 */
@Service
public class SysUserRoleServiceImpl implements SysUserRoleService {

	@Resource
	private SysUserRoleDao sysUserRoleDao;

	/**
    * 新增
    */
	@Override
	public ReturnT<String> insert(SysUserRole sysUserRole) {

		// valid
		if (sysUserRole == null) {
			return new ReturnT<>(ReturnT.FAIL_CODE, "必要参数缺失");
        }

		sysUserRoleDao.insert(sysUserRole);
        return ReturnT.SUCCESS;
	}

	/**
	* 删除
	*/
	@Override
	public ReturnT<String> delete(Long userId) {
		int ret = sysUserRoleDao.delete(userId);
		return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
	}

	/**
	* 批量删除
	*/
	@Override
	public ReturnT<String> batchDelete(List<Long> ids) {
		int ret = sysUserRoleDao.batchDelete(ids);
		return ret > 0 ? ReturnT.SUCCESS : ReturnT.FAIL;
	}

	/**
	* 更新
	*/
	@Override
	public ReturnT<String> update(SysUserRole sysUserRole) {
		int ret = sysUserRoleDao.update(sysUserRole);
		return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
	}

	/**
	* Load查询
	*/
	@Override
	public SysUserRole load(int id) {
		return sysUserRoleDao.load(id);
	}

	/**
	* 分页查询
	*/
	@Override
	public PageInfo pageList(PageInfo pageInfo) {

		List<SysUserRole> pageList = sysUserRoleDao.pageList(pageInfo);
		int totalCount = sysUserRoleDao.pageListCount(pageInfo);

        pageInfo.setResultObject(pageList);
        pageInfo.setTotalRecord(totalCount);
        return pageInfo;
	}

	@Override
	public int saveOrUpdate(List<SysUserRole> sysUserRoleList) {
		return sysUserRoleDao.saveOrUpdate(sysUserRoleList);
	}

}
